package socket_net_code.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class Demo2_Send {
    public static void main(String[] args) throws IOException {
        //创建键盘录入对象
        Scanner sc = new Scanner(System.in);
        //String str = "I want to be a rich man!!!";
        //创建Socket相当于创建码头
        DatagramSocket socket = new DatagramSocket();
        while(true) {
            //获取键盘录入的字符串
            String str = sc.nextLine();
            if("quit".equals(str)) {
                break;
            }
            //创建Packet相当于集装箱
            DatagramPacket packet =
                    new DatagramPacket(
                            str.getBytes(), str.getBytes().length, InetAddress.getByName("192.168.106.194"), 9527);
            socket.send(packet);
        }

        socket.close();
    }


}
